package com.easthome.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easthome.auth.mapper.SysMenuMapper;
import com.easthome.auth.service.SysMenuService;
import com.easthome.common.result.Result;
import com.easthome.common.system.MenuHelper;
import com.easthome.model.system.SysMenu;
import com.easthome.model.system.SysRole;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: 朱敦宇
 * @time: 2023/11/8 20:42
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
    @Override
    public Result findMenu() {

        List<SysMenu> allMenu = baseMapper.selectList(null);
        List<SysMenu> treeMenu=MenuHelper.toTreeMenu(allMenu);
        System.out.println(treeMenu.size());

        return Result.ok(treeMenu);
    }
//    void find(List<SysMenu> sysMenus){
//        for (SysMenu sysMenu : sysMenus) {
//            LambdaQueryWrapper<SysMenu> sysMenuLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            sysMenuLambdaQueryWrapper.eq(SysMenu::getParentId, sysMenu.getId());
//            List<SysMenu> sysMenus1 = baseMapper.selectList(sysMenuLambdaQueryWrapper);
//            if(sysMenus1.size()>0){
//                sysMenu.setChildren(sysMenus1);
//                find(sysMenus1);
//            }
//        }
//    }
}
